#include "server.hpp"

#define host "127.0.0.1"
#define user "yss"
#define passwd "313710"
#define db "gobang"
#define port 3306

void split_test()
{
    std::vector<std::string> v;
    std::string str = "aaa,bbb,,ccc";
    std::string sep = ",";
    Split_Util::splitStr(str, &v, sep);
    for(auto& e : v)
    {
        std::cout << e << " ";
    } 
    std::cout << std::endl;
}
void json_test()
{
    Json::Value root;
    root["name"] = "yss";// 这里给具体数据
    root["age"] = 20;
    std::string str;
    Json_Util::serializa(root, str);
    std::cout << str << std::endl;

    Json::Value val;
    Json_Util::unserializa(str, val);
    std::string name = root["name"].asString();
    int age = root["age"].asInt();
    std::cout << name << std::endl;
    std::cout << age << std::endl;
}
void read_test()
{
    std::string str;
    const std::string file = "./makefile";
    bool ret = File_Util::ReadFile(file, str);
    if(!ret) return;
    std::cout << str << std::endl;
}
void mysql_test()
{
    MYSQL* mysql = Mysql_Util::mysql_create(host, user, passwd, db, port);
    std::string sql = "insert into haha values(2,'李四',23);";
    bool ret = Mysql_Util::mysql_exe(mysql, sql);
    if(!ret) return;
    Mysql_Util::mysql_des(mysql);
}
void log_test()
{
    std::cout << "hellaaa" << std::endl;
    LOG(INFO) << "打印成功" << "\n";
}
void db_test()
{
    user_table ut(host, user, passwd, db, port);
    Json::Value jv;
    // jv["username"] = "张三";
    // jv["password"] = "564789";
    bool ret = ut.lose(2);
    // std::string json_string;
    // Json_Util::serializa(jv, &json_string);
    // std::cout << json_string << std::endl;
}
void online_test()
{
    online_manager om;
    wsserver_t::connection_ptr conn;
    uint64_t uid = 2;
    om.enter_game_hall(uid, conn);
    if(om.is_in_game_hall(uid))
    {
        LOG(INFO) << "在游戏大厅" << "\n";
    }
    else 
    {
        LOG(INFO) << "不在游戏大厅" << "\n";
    }
    om.exit_game_hall(uid);
    if(om.is_in_game_hall(uid))
    {
        LOG(INFO) << "在游戏大厅" << "\n";
    }
    else 
    {
        LOG(INFO) << "不在游戏大厅" << "\n";
    }
}
void room_test()
{
    user_table ut(host, user, passwd, db, port);
    online_manager om;
    room ro(10, &ut, &om);
    room_manage rm(&ut, &om);
    rm.create_room(10, 20);
    matcher ma(&ut, &rm, &om);
}
void server_test()
{
    gobang_server svr(host, user, passwd, db, port);
    svr.Start();
}
int main()
{
    server_test();   
    return 0;
}
